/*   
 * Copyright (c) 2013-2023 LanYoung tech co., LTD. All Rights Reserved.   
 *   
 * This software is the confidential and proprietary information of   
 * LanYoung tech. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with LanYoung tech.   
 *   
 */     
package com.github.ldw4033.spring.controller;

import com.github.ldw4033.spring.domain.User;
import com.github.ldw4033.spring.exception.CustomException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(value = "user")
public class UserController {
	private static Logger log=LoggerFactory.getLogger(UserController.class);
//	@RequestMapping("/showUserListByJson")
//	public @ResponseBody List<User> showUserListByJson(){
//		log.info("showUserListByJson");
//		Calendar calendar = new GregorianCalendar();
//		List<User> userList = new ArrayList<User>();
//		User user1 = new User();
//		user1.setUserName("tom");
//		user1.setRealName("汤姆");
//		calendar.set(1980, 1, 1);
//		user1.setBirthday(calendar.getTime());
//		User user2 = new User();
//		user2.setUserName("john");
//		user2.setRealName("约翰");
//		user2.setBirthday(calendar.getTime());
//		userList.add(user1);
//		userList.add(user2);
//
//		return userList;
//	}
//	@RequestMapping("/showUserListByXml")
//	public @ResponseBody List<User> showUserListByXml(){
//		log.info("showUserListByXml");
//		Calendar calendar = new GregorianCalendar();
//		List<User> userList = new ArrayList<User>();
//		User user1 = new User();
//		user1.setUserName("tom");
//		user1.setRealName("汤姆");
//		calendar.set(1980, 1, 1);
//		user1.setBirthday(calendar.getTime());
//		User user2 = new User();
//		user2.setUserName("john");
//		user2.setRealName("约翰");
//		user2.setBirthday(calendar.getTime());
//		userList.add(user1);
//		userList.add(user2);
//
//		return userList;
//	}
//	@RequestMapping(value="/showUserList",method = RequestMethod.GET,
//			produces = {"application/json", "application/xml"})
//	public @ResponseBody User showUser(){
//		log.info("showUserList");
//		Calendar calendar = new GregorianCalendar();
//
//		User user = new User();
//		user.setUserName("tom");
//		user.setRealName("汤姆");
//		calendar.set(1980, 1, 1);
//		user.setBirthday(calendar.getTime());
//
//		return user;
//	}

	@RequestMapping(value = "create")
	public String userCreateForm() throws CustomException {
		/*if(1==1){
			throw new CustomException("111111111111111");
		}*/
		if(1==1){
			throw new RuntimeException("模拟运行时异常");
		}
		return "user/form";
	}

	@RequestMapping(value = "save",method = RequestMethod.POST)
	public String save(Model model,User user){
		log.debug("user:{}", user);
		model.addAttribute("user",user);
		return "user/form";
	}


	@RequestMapping(value = "/userJson",method = RequestMethod.GET)
	public String userJsonForm(){
		return "user/userJson";
	}

	@RequestMapping(value = "userJson1",method = RequestMethod.POST)
	public @ResponseBody User userJson1(@RequestBody User user){
		log.debug("user:{}", user);
		return user;
	}
	@RequestMapping(value = "userJson2",method = RequestMethod.POST,produces = {"application/json"})
	public @ResponseBody User userJson2(User user){
		log.debug("user:{}", user);
		return user;
	}

}
  